<!--
	作者：offline
	时间：2018-09-03
	描述：会计对账单
-->
<template>
	<div class="m-view-goodsAccountBill m-window">
		<div class="m-condition" v-if="diaShow">
			<el-row :gutter="10">
				<el-form
					:model="ruleForm"
					ref="ruleForm"
					:label-width="labelWidth"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6">
						<el-form-item :label="label" class="rightItem">
							<el-select
								value-key="id"
								v-model="selCompanyCode"
								:placeholder="placeholder"
								@change="companyChange"
								ref="content"
								:disabled="btnDis"
								filterable
								:clearable="accountType==4"
							>
								<el-option
									v-for="item in comOptions"
									:key="item.id"
									:label="item.companyName"
									:value="item"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="申请日期" class="rightItem">
							<el-date-picker
								v-model="applySDate"
								type="date"
								placeholder="开始日期"
								value-format="yyyy-MM-dd"
								:editable="false"
								:clearable="true"
								:picker-options="po1"
								:disabled="btnDis"
							></el-date-picker>
							<!--@change="applySDateChange"-->
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-date-picker
							v-model="applyEDate"
							type="date"
							placeholder="结束日期"
							value-format="yyyy-MM-dd"
							:editable="false"
							:clearable="true"
							:picker-options="po2"
							:disabled="btnDis"
						></el-date-picker>
						<!--@change="applyEDateChange"-->
					</el-col>
					<el-col :span="6">
						<el-form-item label="对账单号" class="rightItem">
							<el-input v-model="accountNo" placeholder="请输入单号" clearable></el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<el-row :gutter="10">
				<el-form
					:model="ruleForm"
					ref="ruleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6" v-if="!btnShow">
						<el-form-item label="供应商" class="rightItem">
							<el-input
								placeholder="请选择供应商"
								v-model="selCusName"
								clearable
								readonly
								@focus="showSupplierDialog"
								@mouseenter.native="mouseEnter"
								@mouseleave.native="mounseLeave"
								:disabled="btnDis"
							>
								<el-button slot="append" icon="el-icon-search" @click="showSupplierDialog"></el-button>
								<span slot="suffix" @click="inputClearSon" class="m-cleanInput" v-show="inputClearBut">
									<i class="el-input_icon el-icon-circle-close el-input__clear"></i>
								</span>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="单据状态" class="rightItem">
							<el-select
								v-model="recCode"
								placeholder="单据状态"
								@change="stateChange"
								clearable
								:disabled="btnDis"
							>
								<el-option
									v-for="item in recOptions"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="签署模式" class="rightItem">
							<el-select
								v-model="signModel"
								placeholder="签署模式"
								@change="stateChange"
								clearable
								:disabled="btnDis"
							>
								<el-option
									v-for="item in modelOptions"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-form>
				<!--<el-col :span="3">
					<el-select v-model="signCode" placeholder="签署状态" clearable >
						<el-option v-for="item in signOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-col>-->
				<el-col :span="2" v-if="btnShow" class="m-floatright">
					<el-button type="primary" @click="del" :disabled="btnDis">删除</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright">
					<el-button type="primary" @click="checkSteps" :disabled="btnDis">查看流程信息</el-button>
				</el-col>
				<el-col :span="2" v-if="signModel==1&&recCode==4" class="m-floatright">
					<el-button type="primary" :disabled="btnDis" @click="printAccount">打印对账函</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright">
					<el-button type="primary" @click="search(1)" :disabled="btnDis">查询</el-button>
				</el-col>
			</el-row>
		</div>
		<div class="m-agTable m-bottom m-top2" v-if="diaShow">
			<accountCheckInfo ref="getAccountInfo" @getClickValue="getClickValue"></accountCheckInfo>
		</div>
		<div class="m-page" v-if="diaShow">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				@prev-click="handlePrevClick"
				@next-click="handleNextClick"
				:current-page="currentPage"
				:page-sizes="[30,50,100,150,200]"
				:page-size="pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="total"
			></el-pagination>
		</div>

		<el-dialog
			title="供应商信息"
			:visible.sync="srmSupplierDialogVisible"
			width="50%"
			:before-close="srmSupplierDialogClose"
			v-dialogDrag
			:close-on-click-modal="false"
			:close-on-press-escape="false"
		>
			<srmSupplierInfo ref="srmSupplierInfo" :layout="layout" @setSrmSupplierInfo="setSrmSupplierInfo"></srmSupplierInfo>
			<!--@setSapSupplierCompanyInfo="getSelectedCompany" :setSelectedSupplierCode="getSelectedSupplierCode"-->
		</el-dialog>

		<!--新增会计对账-->
		<div class="m-window" v-if="!diaShow">
			<accountApplyComponents
				@cancelComponents="cancelComponents"
				:pageLayOut="pageLayOut"
				:authInfo="authInfo"
				:setClickValue="setClickValue"
			></accountApplyComponents>
		</div>
		<!-- 查看流程信息弹窗 -->
		<accountSteps
			:dialogTitle="'会计对账流程信息'"
			:stepsVisible="stepsVisible"
			:stepsData="stepsData"
			:activeIndex="activeIndex"
			@dialogclose="closeSteps"
		></accountSteps>
	</div>
</template>

<script>
import _Api from "@/api";
import accountCheckInfo from "@/views/accountManagement/accountCheckInfo.vue"
import accountApplyComponents from "@/views/accountManagement/accountApplyComponents.vue";
import srmSupplierInfo from "@/components/srmSupplierInfo.vue";
import accountSteps from "@/components/accountSteps.vue";
import constant from "@/public/constant";
import serviceTime from "@/public/serverTime.js";
import Msg from "@/public/message.js";
import { startPrint } from 'lesso-common/webprint';
import fileStream from "@/public/fileStream";
import apienv from '@/api/env';
import waterfall from "async-es/waterfall";
import aes from '@/public/aes';


const ENV = apienv[constant.appenv]

export default {
	data () {
		return {
			label: "",
			labelWidth: '70px',
			ruleForm: {},
			selCusCode: "",
			selCusName: "",
			cusOptions: [],
			selSupplierCode: "",
			supOptions: [],
			selCompanyCode: "",
			comOptions: [],
			accountNo: "",
			//jjc20181014
			applySDate: "",
			applyEDate: "",
			recCode: 2,
			//单据状态
			recOptions: [],
			diaShow: true, //控制显示列表查询界面, 否则显示会计对账单详情界面
			btnShow: true, //控制显示供应商用户相关的控件，否则显示非供应商相关控件
			currentPage: 1,
			pageSize: 30,
			total: 0,
			//optionsShow: false,
			accountInfo: [],
			signCode: "",
			// //签署状态
			// signOptions:[
			// {	value:1,label:"未进行"},
			// {	value:2,label:"进行中"},
			// {	value:3,label:"已完成"}],
			placeholder: "",
			supplierInfo: "",
			//accShow:false,
			pageLayOut: "add",//页面配置，判断当前属于编辑/新增
			setClickValue: {},
			authInfo: [],
			srmSupplierDialogVisible: false,
			layout: {},
			inputClearBut: false,
			btnDis: false,
			po1: {
				disabledDate: this.disabledDate1
			},
			po2: {
				disabledDate: this.disabledDate2
			},
			current: 0,
			textChange: 0,
			// 是否显示流程信息弹窗
			stepsVisible: false,
			// 当前流程数据
			stepsData: [
				{
					name: '供应商提交对账单',
					// prcsUser:'佛山高明森新有限公司',
					prcsDate: '2019-05-26 09:09',
					result: 1
				},
				{
					name: '联塑财务确认',
					// prcsUser:'吴先生',
					prcsDate: '2019-05-29 12:34',
					result: 0
				},
				{
					name: '联塑财务审批',
					// prcsUser:'吴先生',
					prcsDate: '2019-05-29 14:34',
					result: 0
				},
				{
					name: '签署',
					// prcsUser:'吴先生',
					prcsDate: '2019-05-29 15:34',
					result: 0
				},
				{
					name: '完成',
					// prcsUser:'吴先生',
					prcsDate: '2019-05-30 10:09',
					result: 0
				}
			],
			// 步骤进行到哪一步
			activeIndex: 0,
			// 签署模式
			signModel: 0,
			// 签署模式下拉
			modelOptions: [
				{ label: '线上', value: 0 },
				{ label: '线下', value: 1 }
			],
			// 用户类型
			accountType: this.$global.user.userTypeId
		}
	},
	components: {
		accountCheckInfo,
		accountApplyComponents,
		srmSupplierInfo,
		accountSteps
	},
	watch: {
		applyEDate (value) {
			this.current = 1;
		},
		applySDate (value) {
			this.current = 1;
		},
		selCusName (val) {
			this.currentPage = 1;
			this.search();
		},
		accountNo (val) {
			if (val)
				this.textChange = 1;
			else
				this.textChange = 0;
		},
		recCode (value) {
			this.current = 1;
		}
	},
	methods: {
		// 查看流程信息
		checkSteps () {
			var that = this;
			this.stepsData = [];
			var row = this.$refs.getAccountInfo.$refs.agGridComponent.gridOptions.api.getSelectedRows();
			if (row.length > 1) {
				Msg.showPopMsg("提示：不能同时查询多张会计对账单的流程！")
				return;
			} else if (row.length == 0) {
				Msg.showPopMsg("提示：请选择需要查看流程的会计对账单！")
				return;
			}

			var obj = {
				id: row[0].id
			}

			_Api.getAccountBillProcess(obj).then(function (response) {
				var data = response.data;
				if (data.code == 1) {
					if (data.rows.length > 0) {
						data.rows.forEach((item, index) => {
							if (item.processStatus != 0) {
								if (item.processName == '签署') {
									var nameHandle = '';
									var nameHandleOther = '';
									if (item.signState == 2) {
										if (item.curSigner == 1) {
											nameHandle = '供应商已签署'
											nameHandleOther = '联塑未签署'
										} else if (item.curSigner == 2) {
											nameHandle = '联塑已签署'
											nameHandleOther = '供应商未签署'
										}
									} else if (item.signState == 3) {
										if (item.curSigner == 1) {
											nameHandle = '联塑已签署'
											nameHandleOther = '供应商已签署'
										} else if (item.curSigner == 2) {
											nameHandle = '供应商已签署'
											nameHandleOther = '联塑已签署'
										}
									}
									var step = {
										name: item.processName,
										prcsDate: item.signFirstDate,
										prcsDateOther: item.signComDate,
										result: item.processStatus,
										prcsUser: nameHandle,
										prcsUserOther: nameHandleOther
									}
								} else {
									var step = {
										name: item.processName,
										prcsDate: item.handleDate,
										result: item.processStatus
									}
								}

								if (item.processStatus === 2) {
									that.activeIndex = index + 1;
								}
								that.stepsData.push(step);
							} else {
								var step = {
									name: item.processName,
									result: item.processStatus
								}

								that.stepsData.push(step);
							}
						})
					} else {
						Msg.showErrorMsg(data.info);
						return;
					}
				}
			})
			this.stepsVisible = true
		},
		// 打印对账函
		printAccount () {
			let rows = this.$refs.getAccountInfo.$refs.agGridComponent.gridOptions.api.getSelectedRows();
			if (rows.length <= 0) {
				this.$alert("提示：请选择需要打印的对账单", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"
				});
				return;
			}
			let tempType = ''
			if (constant.userAgent == 'web') {
				tempType = rows[0].unConFlag == 0 ? 'accountLetter' : 'accountLetter_1'
				fileStream.getFileInfo(tempType).then((data) => {
					startPrint({
						basicUrl: ENV['srm'], //权限接口地址
						reportUrl: `${ENV['srm']}download2?viewPath=${data.url}&groupName=${data.groupName}`, //打印模板地址
						dataUrl: 'tblAccountbill/letterInfo', //数据接口地址
						params: {
							'token': '',
							'id': rows[0].id
						}, //参数对象
						printType: 'preview'     // 打印方式print直接打印，preview先预览
					})
				}).catch((err) => {
					Msg.showErrorMsg(err)
				})
			} else {
				tempType = rows[0].unConFlag == 0 ? 'accountLetter_pc' : 'accountLetter_1_pc'
				this.getPrintData(rows[0], tempType)
			}
		},
		// 客户端打印
		getPrintData (row, type) {
			const ENCRYPT_KEY = 'lesso2128token11'
			waterfall([
				(callback) => {
					this.$http.getPrintToken().then(({ data }) => {
						let token = aes.encrypt(data, ENCRYPT_KEY);
						callback(null, token);
					}).catch(err => {
						Msg.showErrorMsg(err.data.message)
					})
				},
				(token, callback) => {
					this.$http.getPrintAccountData({ id: row.id, token: token }).then(({ data }) => {
						let printData = data.rows
						callback(null, printData)
					}).catch(err => {
						Msg.showErrorMsg(err.data.message)
					})
				},
				(printData, callback) => {
					if (constant.printType == 'local') {
						ipcRenderer.send("IPCR_M_PRINTLOCAL", {
							type: type,
							rows: printData,
							optype: 'pr',
							isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
						});
					} else {
						fileStream.getFileInfo(type, printData).then((data) => {
							ipcRenderer.send("IPCR_M_PRINT", {
								type: type,
								rows: printData,
								groupName: data.groupName,
								optype: "pr",
								url: data.url,
								isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
							})
						}).catch((err) => {
							Msg.showErrorMsg(err)
						})
					}
				}
			])
		},
		// 状态或签署模式改变回调
		stateChange () {
			this.currentPage = 1
			this.search()
		},
		// 关闭弹窗
		closeSteps () {
			this.stepsVisible = false
		},
		disabledDate1 (time) {
			if (this.applyEDate)
				return time.getTime() > new Date(this.applyEDate).getTime();
		},
		disabledDate2 (time) {
			if (this.applySDate)
				return time.getTime() < (new Date(this.applySDate).getTime() - 3600 * 1000 * 24);
		},
		applySDateChange (params) {
			this.currentPage = 1;
			this.search();
		},
		applyEDateChange (params) {
			this.currentPage = 1;
			this.search();
		},
		mounseLeave () {
			if (this.selCusName != "")
				this.inputClearBut = false;
		},
		mouseEnter () {
			if (this.selCusName != "")
				this.inputClearBut = true;
		},
		inputClearSon () {
			this.selCusCode = "";
			this.selCusName = "";
			this.inputClearBut = false;
		},
		setSrmSupplierInfo (msg) {
			if (msg.length > 0) {
				this.srmSupplierDialogVisible = false;
				this.selCusCode = msg[0].id;
				this.selCusName = msg[0].supplierName;
				// this.inputClearBut = true;
			}
		},
		srmSupplierDialogClose (done) {
			done();
		},
		showSupplierDialog () {
			var that = this;
			if (!this.layout.companyCode) {
				Msg.showPopMsg("提示：请选择公司！")
				this.$refs.content.focus();
				return;
			} else {
				this.srmSupplierDialogVisible = true;
				this.$nextTick(_ => {
					that.$refs.srmSupplierInfo.search();
				});
			}
		},
		companyChange (value) {
			//公司下拉框选择
			if (value) {
				this.layout.companyCode = value.companyCode;
				this.layout.auth = true;
				//this.layout.filterByUser = true;  取消用户权限限制20181205
				if (this.selCusCode)
					this.selCusCode = "";
				if (this.selCusName)
					this.selCusName = "";
			} else {
				if (this.selCusCode)
					this.selCusCode = "";
				if (this.selCusName)
					this.selCusName = "";
				//this.getAuthInfo();
				this.layout = {};
			}
			this.currentPage = 1;
			this.search();
		},
		search (flag) {
			//查询方法
			var obj = {};
			if (this.$global.user.userTypeId == "4") {
				obj.supplierId = constant.supplierId;
				if (obj.supplierId == '') {
					this.$alert("提示：供应商编码不能为空", {
						showClose: false,
						confirmButtonText: "确定",
						customClass: "alertPrompt"
					});
					return;
				}
			} else {
				//非供应商用户时需要传入用户id作为限制条件 取消20181225
				//obj.accId = this.$global.user.id;
				if (this.selCompanyCode == "") {
					Msg.showPopMsg("提示：" + this.placeholder)
					return;
				}
				if (this.selCusCode == "") {
					// this.$alert("提示：请选择供应商", {
					// 	showClose: false,
					// 	confirmButtonText: "确定",
					// 	customClass: "alertPrompt"
					// });
					// return;
				}
				else
					obj.supplierId = this.selCusCode;
			}
			if (this.selCompanyCode != "")
				obj.companyId = this.selCompanyCode.id;
			this.accountNo = this.accountNo.replace(/\s+/g, "");
			if (this.accountNo != "")
				obj.accountNo = this.accountNo;

			//jjc20181014
			if (this.applySDate != "" && this.applySDate != null) {
				obj.begin_date = this.applySDate;
				if (this.applyEDate == "" || this.applyEDate == null)
					obj.end_date = obj.begin_date;
			}
			if (this.applyEDate != "" && this.applyEDate != null) {
				obj.end_date = this.applyEDate;
				if (this.applySDate == "" || this.applySDate == null)
					obj.begin_date = obj.end_date;
			}
			if (obj.begin_date != "" && obj.end_date != "") {
				if (obj.begin_date > obj.end_date) {
					Msg.showPopMsg("提示：开始日期不能大于结束日期")
					return;
				}
			}

			if (this.recCode == "" || !this.recCode)//单据状态
				obj.billState = 0;
			else
				obj.billState = this.recCode;
			if (this.signCode == "" || !this.signCode)//签署状态
				obj.signState = 0;
			else
				obj.signState = this.signCode;
			//				obj.current = this.currentPage;
			if (flag === 1) {
				this.currentPage = 1;
			}
			if (this.current === 0) {
				obj.current = this.currentPage;
			}
			else
				obj.current = 1;
			obj.size = this.pageSize;
			if (this.$global.user.userTypeId == "4")
				obj.userType = 2;
			else
				obj.userType = 1;
			obj.flag = 1;//会计对账管理页面
			obj.signMode = this.signModel
			var that = this;
			this.$refs.getAccountInfo.loading = true;
			this.btnDis = true;
			that.$refs.getAccountInfo.setColumnDefs()
			_Api.getMyAccountList(obj).then(function (response) {
				that.btnDis = false;
				that.current = 0;
				that.textChange = 0;
				var data = response.data;
				that.$refs.getAccountInfo.loading = false;
				if (data.code == "1") {
					that.accountInfo = data.rows;
					// that.total = that.accountInfo.length;
					that.total = data.total;
					that.$refs.getAccountInfo.getDataRows(that.accountInfo);
				} else {
					Msg.showErrorMsg(data.info);
				}
			}).catch((err) => {
				Msg.showErrorMsg(err.data.message);
				that.current = 0;
				that.textChange = 0;
				that.$refs.getAccountInfo.loading = false;
				that.btnDis = false;
			})
		},
		// 			getAuthInfo() {
		// 				//获取当前账号权限公司
		// 				var obj = {};
		// 				if(this.$global.user.userTypeId == 4) {
		// 					obj.account = this.$global.user.userName;
		// 					obj.userType = 2;
		// 				} else if(this.$global.user.userTypeId == 1) {
		// 					obj.account = this.$global.user.oaNum;
		// 					obj.userType = 1;
		// 				}
		// 				var that = this;
		// 				_Api.getAuthInfo(obj).then(function(response) {
		// 					var data = response.data;
		// 					if(data.code == "1") {
		// 						that.comOptions = data.rows.myMstCompany;
		// //						that.cusOptions = data.rows.myMstSupplier;
		// 						that.authInfo  = that.comOptions;
		// 						that.btnDis = false;
		// 					} else {
		// 						that.comOptions = [];
		// 						that.cusOptions = [];
		// 					}
		// 				}).catch(() => {
		// 					that.$alert("操作失败！", {
		// 						showClose: false,
		// 						confirmButton: "确定",
		// 						customClass: "alertFailure"
		// 					});
		// 					that.comOptions = [];
		// 					that.cusOptions = [];
		// 				})
		// 			},
		//单据状态选择
		recCode_change () {
			this.search();
		},
		handleSizeChange (params) {
			this.pageSize = params;
			this.currentPage = 1;
			this.search();
		},
		handleCurrentChange (params) {
			if (this.current === 1 || this.textChange === 1)
				this.currentPage = 1;
			else
				this.currentPage = params;
			this.search();
		},
		handlePrevClick (params) {
			if (this.current === 1 || this.textChange === 1)
				this.currentPage = 1;
			else
				this.currentPage = params;
			// this.handleCurrentChange(this.currentPage);
		},
		handleNextClick (params) {
			if (this.current === 1 || this.textChange === 1)
				this.currentPage = 1;
			else
				this.currentPage = params;
			// this.handleCurrentChange(this.currentPage);
		},
		//新增会计对账
		addAccountCheck () {
			this.diaShow = false;
			//this.accShow = true;
			this.supplierName = this.$global.user.employeeName + ' (' + this.$global.user.userName + ')';
			this.setClickValue = {};
		},
		del () {
			this.$refs.getAccountInfo.getSelectedRow();
		},
		cancelComponents (msg) {
			if (msg.isCancel == true) {
				var that = this;
				//this.accShow = false;
				this.diaShow = true;
				this.pageLayOut = "add";
				this.signModel = msg.signMode
				if (this.selCompanyCode.id) {
					this.$nextTick(_ => {
						that.search();
					})
				}
			}
		},
		getClickValue (msg) {
			if (msg != "" && msg) {
				this.diaShow = false;
				//this.accShow = true;
				this.pageLayOut = "edit";
				this.setClickValue = msg;
			}
		},
		auditAccountData () {
			this.$refs.getAccountInfo.auditSelectedRows();
		},
		abandonAccountData () {
			this.$refs.getAccountInfo.abandonSelectedRows();
		},

		//初始化界面控件
		initControl () {
			if (constant.user.userTypeId == 4) {
				this.btnShow = true;
				this.placeholder = "请选择客户"
				this.label = "客户";
				this.recOptions = [
					{ value: 1, label: "保存" },
					{ value: 2, label: "提交" },
					{ value: 3, label: "已确认" },
					{ value: 4, label: "已审核" },
					{ value: 9, label: "已过期" }
				];
				//默认单据状态：提交
				this.recCode = 2;
			} else {
				this.btnShow = false;
				this.placeholder = "请选择公司";
				this.label = "公司";
				this.labelWidth = '70px';
				this.recOptions = [
					{ value: 1, label: "保存" },
					{ value: 2, label: "提交" },
					{ value: 3, label: "已确认" },
					{ value: 4, label: "已审核" },
					{ value: 9, label: "已过期" }
				];
				this.recCode = 2;
			}
			//默认日期范围 三个月
			var that = this;
			serviceTime.getServiceTime().then((serviceTime) => {
				if (serviceTime) {
					var resultDate;
					var year = serviceTime.getFullYear();
					var month = serviceTime.getMonth() + 1;
					var month2;
					var dataArr = [];
					dataArr.push(serviceTime.Format("yyyy-MM"));
					var day = 0;
					for (var i = 0; i < 2; i++) {
						switch (month) {
							case 1:
								year--;
								month += 11;
								break;
							default:
								month--;
								break;
						}
						month2 = month;
						month2 = (month2 < 10) ? ('0' + month2) : month2;
						resultDate = year + '-' + month2;
						dataArr.push(resultDate);
					}
					for (let i in dataArr) {
						var data = dataArr[i].split('-');
						day += new Date(data[0], data[1], 0).getDate();
					}
					that.applySDate = new Date(serviceTime.getTime() - 3600 * 1000 * 24 * day).Format('yyyy-MM-dd');
				}
				that.applyEDate = serviceTime.Format("yyyy-MM-dd");
			})
		},

		//初始化界面数据源
		intiData () {
			//查询公司列表
			var obj = {};
			if (constant.user.userTypeId == 4) {
				obj.account = constant.user.userName;
				obj.userType = 2;
				obj.flag = 1;
			}
			else {
				obj.account = constant.user.oaNum;
				obj.userType = 1;
				obj.flag = 1
			}
			var that = this;
			_Api.getAuthInfo(obj).then(function (response) {
				var data = response.data;
				if (data.code == "1") {
					that.btnDis = false;
					that.comOptions = data.rows.myMstCompany;
					that.cusOptions = data.rows.myMstSupplier;
					that.authInfo = that.comOptions;
					//默认公司
					if (constant.user.userTypeId != 4) {
						//找登录人所在公司的条目
						for (var i = 0; i < that.comOptions.length; i++) {
							if (that.comOptions[i].companyCode == constant.user.bukrs) {
								that.selCompanyCode = that.comOptions[i];
							}
						}
					}
					else {
						//找第一家公司
						that.selCompanyCode = that.comOptions[0];
					}
					that.layout.companyCode = that.selCompanyCode.companyCode;
					that.layout.auth = true;
					//自动查询
					that.search(1);
				}
				else {
					that.comOptions = [];
					that.cusOptions = [];
				}

			}).catch((err) => {
				Msg.showErrorMsg(err.data.message);
				that.comOptions = [];
				that.cusOptions = [];
			})
		}

	},
	mounted () {
		//初始化控件
		this.initControl();
		//初始化数据源
		this.intiData();
		//			
	}
}
</script>

<style>
</style>